﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace VisionCloud.Domain.UnitOfWork
{
    public interface IUnitOfWork   // : IDisposable
    {
        Task ExecuteAsync(Func<Task> action);

        /// <summary>
        /// 可操控的事务提交(不带返回值)
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        Task OpenTrans(Func<Func<Task<int>>, Task> action);

        /// <summary>
        /// 可操控的事务提交(带返回值)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="func"></param>
        /// <returns></returns>
        Task<T> OpenTrans<T>(Func<Func<Task<int>>, Task<T>> func);

        /// <summary>
        /// 重置事务
        /// </summary>
        /// <returns></returns>
        void Reset();

        /// <summary>
        /// 事务提交
        /// </summary>
        /// <returns></returns>
        Task<int> SaveChangesAsync();

        /// <summary>
        /// 事务提交
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<int> SaveChangesAsync(CancellationToken cancellationToken);
    }
}